

//点击客户基本信息显示客户信息列表
function supplierBaseInfo(){
	
	//获取显示信息列表内容
	//var clientInfo = getClientInfo();
	var clientList = $("#bag").html("");
	var clientPanel = "";
	var clientTable = "";
	//调用根据客户多条件查询出来的列表方法
	//var client = getClientInfo(null,null);
	
	clientPanel = "<div class='panel panel-info'>"+
	 "<!-- Default panel contents -->"+
	  "<div class='panel-heading'>" +
	  	"<div class='row'>"+
	  		"<div class='col-md-6 col-sm-6 col-xs-6'>"+
	  			"<span style='font-size:0.7rem'>供应商基本信息</span>"+
	  		"</div>"+
	  		"<div class='col-md-3 col-sm-3 col-xs-3'>"+
	  		
	  		"</div>"+
	  	"</div>"+
	  	
	  "</div>"+
	  "<div>"+
	  "</div>"+
	  "<div class='row' style='margin-right:0px;margin-top:0.2rem'>"+
	  		"<div class='col-md-2 col-sm-2 col-xs-2'>"+
	  		"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class='btn btn-default' onclick='addSupplier()'>新&nbsp;&nbsp;增</button>"+
	  		"</div>"+
			"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"+
			"<div class='input-group'>"+
	        "<input type='text' class='form-control' id='supplierNames' placeholder='请输入信息'>"+
	        "<span class='input-group-btn'>"+
	          "<button class='btn btn-default' type='button' onclick='supplierSel();'>查询</button>"+
	        "</span>"+
	      "</div>"+
			"</div>"+
	"</div>"+
	  
	  "<!-- Table -->"+
	  "<table class='table' style='text-align:center' id='supplierLists'>"+
	  	"<thead>"+
	  		"<tr>"+
	  		"<th style='text-align:center'>供应商名称</th>"+
	  		"<th style='text-align:center'>供应商联系人</th>"+
	  		"<th style='text-align:center'>客户联系方式</th>"+
	  		"<th style='text-align:center'>供应商地址</th>"+
	  		"<th style='text-align:center'>供应商传真传真</th>"+
	  		"<th style='text-align:center'>操&nbsp;&nbsp;作</th>"+
	  		"</tr>"+
	  	"</thead>"+
	    "<tbody>"+
	    "</tbody>"+
	  "</table>"+
	  "<div class='col-12-md' id='supplierFoot'>"+
	  "</div>"+
	"</div>";
	
		clientList.append(clientPanel);
		//调用显示客户列表信息的方法
		showSupplierInfo(null);
}

//按条件查询客户基本信息
function supplierSel(){
	//获取查询条件
	var data="name="+$("#supplierNames").val();
	showSupplierInfo(data);
}

//显示供应商基本信息
function showSupplierInfo($data){
	
	var client = postMethod("/trade-wzj-web/SupplierInfoContrillerYang/findSupplier","POST",$data);
	
	//获取结果集合
	var list = client.list;
	
	//获取查询条件
	var selCondition = $("#supplierNames").val();
	
	var clientTable="";
	if(list.length>=0){
		for(var i=0;i<list.length;i++){
			clientTable = clientTable+"<tr>"+
    		"<td>"+list[i].supplierName+"</td>"+
    		"<td>"+list[i].supplierContacts+"</td>"+
    		"<td>"+list[i].supplierPhone+"</td>"+
    		"<td>"+list[i].supplierAddress+"</td>"+
    		"<td>"+list[i].supplierFax+"</td>"+
    		"<td><a href='#' onclick='updateSupplierOpen("+list[i].supplierInfoID+","+client.pageNum+",\""+selCondition+"\");'><span class='glyphicon glyphicon-pencil'></span></a>&nbsp;&nbsp;<a href='#' onclick='delSupplierTable("+list[i].supplierInfoID+","+client.pageNum+",\""+selCondition+"\")'><span class='glyphicon glyphicon-remove'></span></a></td>"+
    		"</tr>";
		}
	}
	var tbody = $("#supplierLists tbody").html("");
	tbody.append(clientTable);
	var page = getPageSupplier(client);
	var pageTable = $("#supplierFoot").html("");
	
	pageTable.append(page);
}

//获取页码信息
function getPageSupplier($clientList){
	var page="";
	
	var con = $("#supplierNames").val();
	page = page+"<div class='row' style='margin:0px'>" +
	"<div class='col-md-2 col-sm-2 col-xs-2' style='padding-top:0.7rem'>"+
		"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
	"</div>"+
	"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"
	+"<nav aria-label='Page navigation'>"+
"<ul class='pagination pagination-sm'>";
	if($clientList.prePage>0){
		page = page+"<li><a href='#' onclick='getPagesSupplier("+$clientList.firstPage+",\""+con+"\")'>首页</a></li>"+
		"<li><a href='#' onclick='getPagesSupplier("+$clientList.prePage+",\""+con+"\")'>上一页</a></li>";
				
	}
	if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
		page = page+"<li><a href='#' onclick='getPagesSupplier("+$clientList.nextPage+",\""+con+"\")'>下一页</a></li>"+
		"<li><a href='#' onclick='getPagesSupplier("+$clientList.lastPage+",\""+con+"\")'>末页</a></li>";
	}
	page = page+"</li>"+
"</ul>"+
"</nav>"+
"</div>"+
"</div>";
	return page;
	
}

//分页功能
function getPagesSupplier($page,$object){
	var data="name="+$object+"&currentPages="+$page;
	showSupplierInfo(data);
}


//删除客户基本信息
function delSupplierTable($delId,$pageNum,$object){
	var ensure = confirm("确定删除此信息吗?");
	
	if(ensure==false){
		return;
	}
	//获取删除条件
	var data="supplierInfoId="+$delId;
	var url="/trade-wzj-web/testYu/supplierInfoDel";
	var result = postMethod(url,"POST",data);
	console.info(result);
	if(result){
		alert("删除成功!");
	}else{
		alert(result);
	}
	
	var selData = "name="+$object+"&currentPages="+$pageNum;
	showSupplierInfo(selData);
}


//新增客户基本信息
function addSupplier(){
	var tables = $("#addSupplierTable");
	tables.html("");
	var tableAdd = "<tr>" +
			"<td>供应商名称*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='此信息不能为空' name='supplierName' ></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商联系人*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='不能为空' name='supplierContacts'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商联系方式*：</td>" +
			"<td><input type='text' name='supplierPhone' datatype='*' nullmsg='不能为空'  class='form-control'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商地址*：</td>" +
			"<td><input type='text' name='supplierAddress' datatype='*' nullmsg='客户地址不能为空' class='form-control'></td>"+
			"<td></td>"+
			"</tr>"+
			
			"<tr>" +
			"<td>传真*：</td>" +
			"<td><input type='text' name='supplierFax' datatype='*' nullmsg='不能为空' class='form-control'></td>"+
			"<td></td>"+
			"</tr>";
	tables.append(tableAdd);
	$("#addSupplierModal").modal("toggle");
}

//保存客户基本信息添加
function saveSupplierF(){
	var addSupplierForm = $("#addSupplierForm").Validform({
		tiptype:1
	});
	
	var bool = addSupplierForm.check();
	if(bool==false){
		$("#addSupplierS").popover("toggle");
		return;
	}
	var data = $("#addSupplierForm").serialize();
	//获取提交路径
	var url="/trade-wzj-web/tests/gysAdd";
	var flag = postMethod(url,"POST",data);
	
	if(flag){
		alert("添加成功!");
		
	}else{
		alert("添加失败");
	}
	showSupplierInfo(null);
}

//打开要修改的客户基本信息页面
function updateSupplierOpen($updateId,$num,$obj){
	//定义要修改的对象
	var data="id="+$updateId;
	//获取提交路径
	var url="/trade-wzj-web/SupplierInfoContrillerYang/getSupplierInfoById";
	//调用提交方法
	var result = postMethod(url,"POST",data);
	var tables = $("#updateSupplierTable").html("");
	
	var tableAdd = "<tr>" +
			"<td>供应商名称*：</td>" +
			"<td><input type='text' class='form-control' readonly='readonly' value='"+result.supplierName+"'></td>"+
			"<td><input type='hidden' name='supplierInfoID' value='"+result.supplierInfoID+"'></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商联系人*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='不能为空' name='supplierContacts' value='"+result.supplierContacts+"' required></td>"+
			"<td><input type='hidden' id='updateSupNum' value='"+$num+"'></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商联系方式*：</td>" +
			"<td><input type='text' name='supplierPhone' datatype='*' nullmsg='号码不能为空!' class='form-control' value='"+result.supplierPhone+"' required></td>"+
			"<td><input type='hidden' id='supplierObject' value='"+$obj+"'></td>"+
			"</tr>"+
			"<tr>" +
			"<td>供应商地址*：</td>" +
			"<td><input type='text' value='"+result.supplierAddress+"' name='supplierAddress' datatype='*' class='form-control' required></td>"+
			"<td></td>"+
			"</tr>"+
			
			"<tr>" +
			"<td>传真*：</td>" +
			"<td><input type='text' value='"+result.supplierFax+"' name='supplierFax' datatype='*' class='form-control' required></td>"+
			"<td></td>"+
			"</tr>";
	tables.append(tableAdd);
	$("#updateSupplierModal").modal("show");
}

//修改客户基本信息按钮方法
function updateSupplier(){
	
	var updateSupplierForm = $("#updateSupplierForm").Validform({
		tiptype:1
	});
	var bool = updateSupplierForm.check();
	if(!bool){
		$("#updateSupplierS").popover("toggle");
		return;
	}
	var formData = $("#updateSupplierForm").serialize();
	//获取提交路径
	var url="/trade-wzj-web/SupplierInfoContrillerYang/updateSupplier";
	var result = postMethod(url,"POST",formData);
	if(result){
		alert("修改成功!");
	}else{
		alert("修改失败!");
	}
	var $data="name="+$("#supplierObject").val()+"&currentPages="+$("#updateSupNum").val();
	showSupplierInfo($data);
	$("#updateSupplierModal").modal("hide");
	
}
